let table_name = "company_card_table";
let table_data_url = "/sys/company/card/list";
let number_list = "<'row'<'#mytool.col-xs-3'><'col-xs-9'>><'row'<'.col-xs-12'tr>><'row'<'#num_menu.col-xs-2'l><'col-xs-10'p>>";

function action_status() {
}

let dataManage = {
    currentItem: null,
    fuzzySearch: true,
    getQueryCondition: function (data) {
        let param = {};
        param.companyName = $('#company_name').val();
        param.start = data.start;
        param.length = data.length;
        return JSON.stringify(param);
    },
};

let returnData = {
    getDate: [
        {
            className: "ellipsis",
            data: "",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "companyName",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },
        {
            className: "ellipsis",
            data: "address",
            orderable: false,
            width: "50px",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
        }, {
            className: "ellipsis",
            data: "category",
            render: function (data, type, row, meta) {
                if (row.category === 0) {
                    return '加工商';
                }else if (row.category === 1) {
                    return '模具商';
                }else {
                    return '设备商';
                }
            },
            orderable: false,
            width: "50px"
        },{
            className: "ellipsis",
            data: "linkMan",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },{
            className: "ellipsis",
            data: "mobile",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },{
            className: "ellipsis",
            data: "tellNumber",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "picture",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },{
            className: "ellipsis",
            data: "",
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                let button = '';
                if (row.status === 0) {
                    button += '<button class="btn btn-sm btn-danger" onclick=update_status(' + row.id + ',1)>下架</button>'
                } else {
                    button += '<button class="btn btn-sm btn-danger" onclick=update_status(' + row.id + ',0)>上架</button>';
                }
                button += '<button class="btn btn-sm btn-success" onclick=send_official(' + row.bossId + ')>发送官方消息</button>';
                button += '<button class="btn btn-sm btn-primary" onclick=company_card_detail(' + row.bossId + ')>详情</button>';
                button += '<button class="btn btn-sm btn-success" onclick=position_info(' + row.bossId + ')>招聘职位</button>';
                return button;
            }
        }
    ]
}

function foot_info(result) {
}

function createdRow(row, data, index) {
    if (data.role) {
        $(row).addClass("info");
    }
}

function drawCallback(settings) {
}

function search_company_card() {
    find();
}

function fn_draw_call_back() {
}

function update_status(companyCardId, type) {
    HttpUtils.post_json('/sys/company/card/update/status', JSON.stringify({
        'id': companyCardId,
        'status': type,
    }), function (result) {
        success_msg("更新成功", function () {
            $('#change_user_member_status_modal').modal('hide');
            find();
        });
    });
}


function send_official(userId) {
    $('#user_member_id').val(userId);
    $('#send_official_msg_modal').modal('show')
}

modalClose('send_official_msg_modal', function () {
    $('#user_member_id').val('');
    $('#msg').val('');
});

function send_to_user() {
    let userId = $('#user_member_id').val();
    let msg = $('#msg').val();
    if (isNull(msg)) {
        wrong_msg("请填写消息");
        return false;
    }
    HttpUtils.post_json('/sys/user/official/msg', JSON.stringify({
        'id': userId,
        'msg': msg
    }), function (result) {
        success_msg("发送成功", function () {
            $('#send_official_msg_modal').modal('hide');
            find();
        });
    });
}

function company_card_detail(id) {
    HttpUtils.form_self('/sys/company/card/detail', {"id": id})
}

function position_info(bossId) {
    window.location.href="/sys/position/index?boss="+bossId
}